function zoomToKey(zoom) {
  return zoom.toString()
}

const totalWidthCache = {}

class DocViewSizeHelper {
  static getTotalWidth(zoom) {
    if (totalWidthCache[zoomToKey(zoom)]) {
      return totalWidthCache[zoomToKey(zoom)]
    }
    else {
      const pagesInfo = window.manifestInfo.PagesInfo;
      const totalWidth = pagesInfo.reduce((previousValue, pageInfo) => {
        return Math.max(previousValue, pageInfo.width * 1.333 * zoom);
      }, 0);
      totalWidthCache[zoomToKey(zoom)] = totalWidth;
      return totalWidth;
    }
  }

  static getPageSize(pageIndex, zoom) {
    const pagesInfo = window.manifestInfo.PagesInfo;
    if (pageIndex >= 0 && pageIndex < pagesInfo.length) {
      return {
        width: pagesInfo[pageIndex].width * 1.333 * zoom,
        height: pagesInfo[pageIndex].height * 1.333 * zoom + 20
      }
    }
    else {
      return {
        width: 0,
        height: 0
      }
    }
  }
  static getDefaultRowHeight(zoom) {
    return DocViewSizeHelper.getPageSize(0, zoom).height;
  }
  static getDefaultRowWidth(zoom) {
    return DocViewSizeHelper.getTotalWidth(zoom);
  }
}

export default DocViewSizeHelper;